home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1997 January: Mac OS SDK / Dev.CD Jan 97 SDK2.toast / Development Kits (Disc 2) / OpenDoc Development Framework / ODFDev / Clock / Sources / Frame.cpp < prev    next >
Encoding:
Text File  |  1996-09-17  |  8.6 KB  |  326 lines  |  [TEXT/MPS ]

  1. //========================================================================================
  2. //
  3. //    File:                Frame.cpp
  4. //    Release Version:    $ ODF 2 $
  5. //
  6. //    Copyright:    (c) 1993 - 1996 by Apple Computer, Inc., all rights reserved.
  7. //
  8. //========================================================================================
  9.  
  10. #ifndef FRAME_H
  11. #include "Frame.h"
  12. #endif
  13.  
  14. #ifndef PART_H
  15. #include "Part.h"
  16. #endif
  17.  
  18. #ifndef VIEW_H
  19. #include "View.h"
  20. #endif
  21.  
  22. #ifndef DEFINES_K
  23. #include "Defines.k"
  24. #endif
  25.  
  26. #ifndef CONTENT_H
  27. #include "Content.h"
  28. #endif
  29.  
  30. // ----- Part Layer -----
  31.  
  32. #ifndef FWUTIL_H
  33. #include "FWUtil.h"
  34. #endif
  35.  
  36. #ifndef FWITERS_H
  37. #include "FWIters.h"
  38. #endif
  39.  
  40. #ifndef FWCONTXT_H
  41. #include "FWContxt.h"
  42. #endif
  43.  
  44. #ifndef FWGROWBX_H
  45. #include "FWGrowBx.h"
  46. #endif
  47.  
  48. #ifndef FWSCLBAR_H
  49. #include "FWSclBar.h"
  50. #endif
  51.  
  52. // ----- OS Layer -----
  53.  
  54. #ifndef FWTXTSHP_H
  55. #include "FWTxtShp.h"
  56. #endif
  57.  
  58. #ifndef FWRECSHP_H
  59. #include "FWRecShp.h"
  60. #endif
  61.  
  62. #ifndef FWLINSHP_H
  63. #include "FWLinShp.h"
  64. #endif
  65.  
  66. #ifndef FWOVLSHP_H
  67. #include "FWOvlShp.h"
  68. #endif
  69.  
  70. #ifndef FWODGEOM_H
  71. #include "FWODGeom.h"
  72. #endif
  73.  
  74. #ifndef FWTXTBOX_H
  75. #include "FWTxtBox.h"
  76. #endif
  77.  
  78. #ifndef FWCFMRES_H
  79. #include "FWCFMRes.h"
  80. #endif
  81.  
  82. #ifndef FWRESACC_H
  83. #include "FWResAcc.h"
  84. #endif
  85.  
  86. #ifndef FWRESTYP_H
  87. #include "FWResTyp.h"
  88. #endif
  89.  
  90. #ifndef FWFXMATH_H
  91. #include "FWFxMath.h"
  92. #endif
  93.  
  94. #ifndef FWSCRCON_H
  95. #include "FWScrCon.h"
  96. #endif
  97.  
  98. #ifndef FWSUSINK_H
  99. #include "FWSUSink.h"
  100. #endif
  101.  
  102. #ifndef FWMNUBAR_H
  103. #include "FWMnuBar.h"
  104. #endif
  105.  
  106. //========================================================================================
  107. // RunTime information
  108. //========================================================================================
  109.  
  110. #ifdef FW_BUILD_MAC
  111. #pragma segment odfclock
  112. #endif
  113.  
  114. //========================================================================================
  115. // class CClockFrame
  116. //========================================================================================
  117.  
  118. FW_DEFINE_AUTO(CClockFrame)
  119.     
  120. //----------------------------------------------------------------------------------------
  121. // CClockFrame::CClockFrame
  122. //----------------------------------------------------------------------------------------
  123.  
  124. CClockFrame::CClockFrame(Environment* ev, ODFrame* odFrame, 
  125.                         FW_CPresentation* presentation, 
  126.                         CClockPart* clockPart,
  127.                         CClockContent* clockContent) :
  128.     FW_CFrame(ev, odFrame, presentation, clockPart),
  129.     fClockPart(clockPart),
  130.     fBackgroundColor(FW_kRGBWhite),
  131.     fClockContent(clockContent)
  132.  
  133. {    
  134.     SetAdoptsContainerProperties(ev, TRUE);
  135.     
  136.     FW_DO_NOT_DEAD_STRIP(CAnalogView);
  137.     FW_DO_NOT_DEAD_STRIP(CDigitalView);
  138.     FW_DO_NOT_DEAD_STRIP(FW_CGrowBox);
  139. }
  140.  
  141. //----------------------------------------------------------------------------------------
  142. // CClockFrame::~CClockFrame
  143. //----------------------------------------------------------------------------------------
  144.  
  145. CClockFrame::~CClockFrame()
  146. {
  147. }
  148.  
  149. //----------------------------------------------------------------------------------------
  150. // CClockFrame::FacetAdded
  151. //----------------------------------------------------------------------------------------
  152.  
  153. void CClockFrame::FacetAdded(Environment* ev, ODFacet* facet, unsigned short facetCount)
  154. {
  155.     FW_CFrame::FacetAdded(ev, facet, facetCount);
  156.     
  157.     if (facetCount == 1)
  158.         this->UpdateUsedAndActiveShapes(ev);
  159. }
  160.         
  161. //----------------------------------------------------------------------------------------
  162. // CClockFrame::Draw
  163. //----------------------------------------------------------------------------------------
  164.  
  165. void CClockFrame::Draw(Environment* ev, ODFacet* odFacet, ODShape* invalidShape)
  166. {    
  167.     // [HLX] This will be moved into an erase adorner
  168.     if (IsRoot(ev))
  169.     {
  170.         FW_CViewContext vc(ev, this, odFacet, invalidShape);
  171.  
  172.         FW_CRect invalidRect;
  173.         vc.GetClipRect(invalidRect);
  174.  
  175. #ifdef FW_BUILD_MAC
  176.         FW_CInk ink(FW_kRGBWhite,
  177.                     FW_kRGBWhite,
  178.                     FW_kErase);
  179. #else
  180.         FW_CInk ink(FW_CColor(::GetSysColor(COLOR_WINDOWTEXT), 0),
  181.                     FW_CColor(::GetSysColor(COLOR_APPWORKSPACE), 0),
  182.                     FW_kErase);
  183. #endif
  184.         FW_CRectShape::RenderRect(vc, invalidRect, FW_kFill, ink);
  185.     }
  186. }
  187.  
  188. //----------------------------------------------------------------------------------------
  189. //    CClockFrame::PresentationChanged
  190. //----------------------------------------------------------------------------------------
  191.  
  192. void CClockFrame::PresentationChanged(Environment* ev)
  193. {
  194.     FW_CFrame::PresentationChanged(ev);
  195.  
  196.     UpdateUsedAndActiveShapes(ev);
  197. }
  198.  
  199. //----------------------------------------------------------------------------------------
  200. //    CClockFrame::SetBackgroundColor
  201. //----------------------------------------------------------------------------------------
  202.  
  203. void CClockFrame::SetBackgroundColor(Environment* ev, FW_CColor& newColor)
  204. {
  205.     if (newColor != fBackgroundColor)
  206.     {
  207.         fBackgroundColor = newColor;
  208.         Invalidate(ev);
  209.     }
  210. }
  211.  
  212. //----------------------------------------------------------------------------------------
  213. //    CClockFrame::GetBackgroundColor
  214. //----------------------------------------------------------------------------------------
  215.  
  216. void CClockFrame::GetBackgroundColor(FW_CColor* newColor) const
  217. {
  218.     *newColor = fBackgroundColor;
  219. }
  220.  
  221. //----------------------------------------------------------------------------------------
  222. //    CClockFrame::AdjustUsedShape
  223. //----------------------------------------------------------------------------------------
  224. //    'suggestedUsedShape' is equal to the frame shape
  225.  
  226. ODShape* CClockFrame::AdjustUsedShape(Environment* ev, ODShape* suggestedUsedShape)
  227. {    
  228.     FW_ASSERT(GetViewType(ev) == FW_CPart::fgViewAsFrameToken);
  229.         
  230.     FW_CRect usedRect = FW_GetShapeBoundingBox(ev, suggestedUsedShape);
  231.  
  232.     CClockView* clockView = GetClockView(ev);
  233.     if (clockView == NULL)
  234.         return FW_CFrame::AdjustUsedShape(ev, suggestedUsedShape);
  235.     else    
  236.         return clockView->CreateUsedShape(ev, usedRect);
  237. }
  238.  
  239. //----------------------------------------------------------------------------------------
  240. //    CClockFrame::AdjustActiveShape
  241. //----------------------------------------------------------------------------------------
  242. //    [HLX] Because OpenDoc uses the Frame shape as the default active shape I need to 
  243. //    adjust my active shape too.
  244.  
  245. ODShape* CClockFrame::AdjustActiveShape(Environment* ev, ODFacet* facet, ODShape* suggestedActiveShape)
  246. {
  247. FW_UNUSED(facet);
  248.     FW_ASSERT(GetViewType(ev) == FW_CPart::fgViewAsFrameToken);
  249.  
  250.     suggestedActiveShape->Acquire(ev);
  251.     return suggestedActiveShape;
  252. }
  253.  
  254. //----------------------------------------------------------------------------------------
  255. //     CClockFrame::AdoptContainingPartProperties
  256. //----------------------------------------------------------------------------------------
  257.  
  258. void CClockFrame::AdoptContainingPartProperties(Environment* ev, 
  259.                                                 ODStorageUnit* propertyUnit)
  260. {
  261.     FW_CColor newColor = FW_kRGBWhite;
  262.     
  263.     if (fClockPart->UseContainerColor() && propertyUnit && propertyUnit->Exists(ev, kBackgroundColorProp, kBackgroundColorValue, 0))
  264.     {
  265.         FW_PStorageUnitSink suSink(ev, propertyUnit, kBackgroundColorProp, kBackgroundColorValue);
  266.         FW_PBufferedSink sink(ev, suSink);
  267.         FW_CReadableStream stream(sink);
  268.         
  269.         stream >> newColor;
  270.     }
  271.     
  272.     SetBackgroundColor(ev, newColor);
  273. }
  274.  
  275. //----------------------------------------------------------------------------------------
  276. //     CClockFrame::GetClockView
  277. //----------------------------------------------------------------------------------------
  278.  
  279. CClockView* CClockFrame::GetClockView(Environment* ev) const
  280. {
  281.     return (CClockView*)FindViewByID(ev, kClockViewID);
  282. }
  283.  
  284. //----------------------------------------------------------------------------------------
  285. // CClockFrame::DoAdjustMenus
  286. //----------------------------------------------------------------------------------------
  287.  
  288. FW_Handled CClockFrame::DoAdjustMenus(Environment* ev, FW_CMenuBar* menuBar, FW_Boolean hasMenuFocus, FW_Boolean isRoot)
  289. {
  290. FW_UNUSED(isRoot);
  291.     if (hasMenuFocus)
  292.         menuBar->EnableAndToggleCommand(ev, cClockType, TRUE, !fClockPart->IsAnalog(GetPresentation(ev)));    
  293.         
  294.     return FW_kNotHandled;
  295. }
  296.  
  297. //------------------------------------------------------------------------------
  298. // CClockFrame::DoMenu
  299. //------------------------------------------------------------------------------
  300.  
  301. FW_Handled CClockFrame::DoMenu(Environment* ev, const FW_CMenuEvent& theMenuEvent)
  302. {
  303.     FW_Handled menuHandled = FW_kHandled;
  304.     
  305.     switch (theMenuEvent.GetCommandID(ev))
  306.     {
  307.         case cClockType:
  308.             {
  309.                 FW_CPresentation* previousPresentation = GetPresentation(ev);
  310.                 FW_CPresentation* currentPresentation = fClockPart->SwitchPresentation(previousPresentation);
  311.                 ChangePresentation(ev, currentPresentation);
  312.  
  313.                 currentPresentation->ContentUpdated(ev);
  314.  
  315.                 GetPart(ev)->Changed(ev);    // document has changed (enable Save menu item)
  316.             }
  317.             break;
  318.                 
  319.         default:
  320.             menuHandled = FW_kNotHandled;
  321.     }            
  322.     
  323.     return menuHandled;
  324. }
  325.  
  326.